/**
使用全局变量进行线程的信息交互
*/
package main

import (
	"fmt"
	"sync"
	"time"
)

var (
	sum = make(map[int]uint64)
	lock = sync.Mutex{}
)

type task struct {
	n int
}

func calc(t *task) {
	var res uint64
	res = 1
	for i := 1; i <= t.n; i++ {
		res *= uint64(i)
	}
	lock.Lock()
	sum[t.n] = res
	lock.Unlock()

}

func main() {
	for i := 1; i < 16; i++ {
		t := &task{n: i}
		go calc(t)
	}
	time.Sleep(time.Second * 10)
	lock.Lock()
	for k, v := range sum {
		fmt.Printf("[%d!] = %v \n", k, v)
	}
	lock.Unlock()

}
